﻿using OpticalPowerMeter.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Globalization;
using System.Windows;

namespace OpticalPowerMeter.Converts
{
    /// <summary>
    /// 将传入的MeterName枚举转为字符串，主要用于显示在自定义的光功控件上显示
    /// 继承与IValueConverter接口
    /// </summary>
    [ValueConversion(typeof(MeterName), typeof(string))]
    public class MeterNameConverter : IValueConverter
    {
        /// <summary>
        /// 将传入的枚举MerterName转为对应的string
        /// </summary>
        /// <param name="value">枚举对象</param>
        /// <param name="targetType">未使用</param>
        /// <param name="parameter">未使用</param>
        /// <param name="culture">未使用</param>
        /// <returns>string - MeterName对应的string</returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //throw new NotImplementedException();
            MeterName source = (MeterName)value;
            switch (source)
            {
                case MeterName.Sample:
                    return "S";
                case MeterName.One:
                    return "1";
                case MeterName.Two:
                    return "2";
                case MeterName.Three:
                    return "3";
                case MeterName.Four:
                    return "4";
                case MeterName.Five:
                    return "5";
                case MeterName.Six:
                    return "6";
                case MeterName.Seven:
                    return "7";
                default:
                    return DependencyProperty.UnsetValue;
            }
        }

        /// <summary>
        /// IValueConverter继承的方法，本地未做任何实现
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            //throw new NotImplementedException();
            return DependencyProperty.UnsetValue;
        }
    }
}
